﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace RM2012Mobile
{
    #region Utitlies
    public static class Utilities
    {
        public static string InvoiceIdPublic = String.Empty;
        public static string TablesNamePublic = String.Empty;
        public static string UsernamePublic = String.Empty;
        public static string FullNamePublic = String.Empty;
        public static string GroupNamePublic = String.Empty;

        public static string getMD5Hash(string password)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(password);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                sb.Append(b.ToString("x2").ToLower());
            }
            string hash = sb.ToString();
            return hash;
        }

        public static string CreateMessage(string tablesId, string tablesName, string invoiceId, string menuId, string menuName, string objectName, string action, string numOld, string numNew, string username, string fullname, string groupname, String time)
        {
            string content = "<Message>";
            content = content + "<Tables>";
            content = content + "<TablesId>" + tablesId + "</TablesId>";
            content = content + "<TablesName>" + tablesName + "</TablesName>";
            content = content + "</Tables>";
            content = content + "<Invoice>";
            content = content + "<InvoiceId>" + invoiceId + "</InvoiceId>";
            content = content + "</Invoice>";
            content = content + "<Menu>";
            content = content + "<MenuId>" + menuId + "</MenuId>";
            content = content + "<MenuName>" + menuName + "</MenuName>";
            content = content + "</Menu>";
            content = content + "<Working>";
            content = content + "<Objects>" + objectName + "</Objects>";
            content = content + "<Action>" + action + "</Action>";
            content = content + "</Working>";
            content = content + "<Quantity>";
            content = content + "<NumericOld>" + numOld + "</NumericOld>";
            content = content + "<NumericNew>" + numNew + "</NumericNew>";
            content = content + "</Quantity>";
            content = content + "<UserInfo>";
            content = content + "<UserName>" + username + "</UserName>";
            content = content + "<FullName>" + fullname + "</FullName>";
            content = content + "<GroupName>" + groupname + "</GroupName>";
            content = content + "</UserInfo>";
            content = content + "<Time>" + time + "</Time>";
            content = content + "</Message>";
            return content;
        }

        public static string GetNow()
        {
            DateTime dateNow = DateTime.Now;
            string _year = dateNow.Year.ToString();
            string _month = dateNow.Month.ToString();
            if (dateNow.Month < 10)
            {
                _month = "0" + dateNow.Month.ToString();
            }
            string _day = dateNow.Day.ToString();
            if (dateNow.Day < 10)
            {
                _day = "0" + dateNow.Day.ToString();
            }
            string _hour = dateNow.Hour.ToString();
            if (dateNow.Hour < 10)
            {
                _hour = "0" + dateNow.Hour.ToString();
            }
            string _minute = dateNow.Minute.ToString();
            if (dateNow.Minute < 10)
            {
                _minute = "0" + dateNow.Minute.ToString();
            }
            string _second = dateNow.Second.ToString();
            if (dateNow.Second < 10)
            {
                _second = "0" + dateNow.Second.ToString();
            }
            string time = _year + _month + _day + _hour + _minute + _second;
            return time;
        }
    }
    #endregion

    #region Show Form
    public static class ShowForm
    {
        #region Fields
        public static frmLogin m_FrmLogin = null;
        public static frmUserGroup m_FrmUserGroup = null;
        public static frmTables m_FrmTables = null;
        public static frmTCPIP m_FrmTCPIP = null;
        public static frmBooking m_FrmBooking = null;
        public static frmMenu m_FrmMenu = null;
        public static frmServe m_FrmServe = null;
        public static frmTablesEmpty m_FrmTablesEmpty = null;
        public static frmCustomer m_FrmCustomer = null;
        public static frmTablesServing m_FrmTablesServing = null;
        public static frmInvoiceDetail m_FrmInvoiceDetail = null;
        #endregion

        #region Show Form Dang Nhap
        public static void ShowFormDangNhap()
        {
            if (m_FrmLogin == null || m_FrmLogin.IsDisposed)
            {
                m_FrmLogin = new frmLogin();
                m_FrmLogin.Show();
            } 
            else
            {
                m_FrmLogin.Activate();
            }
        }
        #endregion

        #region Show Form Nhom Nguoi Dung
        public static void ShowFormUserGroup()
        {
            if (m_FrmUserGroup == null || m_FrmUserGroup.IsDisposed)
            {
                m_FrmUserGroup = new frmUserGroup();
                m_FrmUserGroup.Show();
            }
            else
            {
                m_FrmUserGroup.Activate();
            }
        }
        #endregion

        #region Show Form Ban
        public static void ShowFormTables()
        {
            if (m_FrmTables == null || m_FrmTables.IsDisposed)
            {
                m_FrmTables = new frmTables();
                m_FrmTables.Show();
            }
            else
            {
                m_FrmTables.Activate();
            }
        }

        public static void ShowFormTablesEmpty()
        {
            if (m_FrmTablesEmpty == null || m_FrmTablesEmpty.IsDisposed)
            {
                m_FrmTablesEmpty = new frmTablesEmpty();
                m_FrmTablesEmpty.Show();
            }
            else
            {
                m_FrmTablesEmpty.Activate();
            }
        }

        public static void ShowFormTablesServing()
        {
            if (m_FrmTablesServing == null || m_FrmTablesServing.IsDisposed)
            {
                m_FrmTablesServing = new frmTablesServing();
                m_FrmTablesServing.Show();
            }
            else
            {
                m_FrmTablesServing.Activate();
            }
        }

        public static void ShowFormInvoiceDetail()
        {
            if (m_FrmInvoiceDetail == null || m_FrmInvoiceDetail.IsDisposed)
            {
                m_FrmInvoiceDetail = new frmInvoiceDetail();
                m_FrmInvoiceDetail.Show();
            }
            else
            {
                m_FrmInvoiceDetail.Activate();
            }
        }
        #endregion

        #region Show Form Khach Hang
        public static void ShowFormCustomer()
        {
            if (m_FrmCustomer == null || m_FrmCustomer.IsDisposed)
            {
                m_FrmCustomer = new frmCustomer();
                m_FrmCustomer.Show();
            }
            else
            {
                m_FrmCustomer.Activate();
            }
        }
        #endregion

        #region Show Form Dat Truoc
        public static void ShowFormBooking()
        {
            if (m_FrmBooking == null || m_FrmBooking.IsDisposed)
            {
                m_FrmBooking = new frmBooking();
                m_FrmBooking.Show();
            }
            else
            {
                m_FrmBooking.Activate();
            }
        }
        #endregion

        #region Show Form Mon Phuc Vu
        public static void ShowFormMenu()
        {
            if (m_FrmMenu == null || m_FrmMenu.IsDisposed)
            {
                m_FrmMenu = new frmMenu();
                m_FrmMenu.Show();
            }
            else
            {
                m_FrmMenu.Activate();
            }
        }
        #endregion

        #region Show Form Phuc Vu
        public static void ShowFormServe()
        {
            if (m_FrmServe == null || m_FrmServe.IsDisposed)
            {
                m_FrmServe = new frmServe();
                m_FrmServe.Show();
            }
            else
            {
                m_FrmServe.Activate();
            }
        }
        #endregion

        #region Show Form TCP/IP
        public static void ShowFormTCPIP()
        {
            if (m_FrmTCPIP == null || m_FrmTCPIP.IsDisposed)
            {
                m_FrmTCPIP = new frmTCPIP();
                m_FrmTCPIP.Show();
            }
            else
            {
                m_FrmTCPIP.Activate();
            }
        }
        #endregion
    }
    #endregion
}
